﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace GameXNA_Master
{
    public class TutorialMenu : Menu
    {
        public enum voice { Indietro };

        public int selectedVoice = 0;
        public string[] voiceText = new string[] { "INDIETRO" };
        public int nrVoices = Enum.GetNames(typeof(voice)).Length;

        public Vector2 starPosition;

        KeyboardState kb;
        KeyboardState oldKb;


        Game game;
        InputService input_service;
        RenderingData rendering_data;
        float rotateStar = 0;

        SpriteFont menufont;
        Texture2D tutorial;
        Texture2D selectionTexture;


        public event Action iMoveUp_Menu;
        public event Action iMoveDown_Menu;
        public event Action iMoveLeft_Menu;
        public event Action iMoveRight_Menu;
        public event Action iConfirm_Menu;

        public TutorialMenu(Game game)
        {
            this.game = game;
            this.input_service = (InputService)game.Services.GetService(typeof(InputService));
            this.rendering_data = (RenderingData)game.Services.GetService(typeof(RenderingData));
            this.menufont = game.Content.Load<SpriteFont>("matrix");
            this.selectionTexture = game.Content.Load<Texture2D>(@"Menu\star");
            this.tutorial = game.Content.Load<Texture2D>(@"Menu\comandi");
            iConfirm_Menu += () =>
            {
                menu_selezionato = 0;
            };
        }


        public void MoveUp()
        {
            if (iMoveUp_Menu != null)
                iMoveUp_Menu();
        }

        public void MoveDown()
        {
            if (iMoveUp_Menu != null)
                iMoveDown_Menu();
        }

        public void MoveLeft()
        {
            if (iMoveLeft_Menu != null)
                iMoveLeft_Menu();
        }
        public void MoveRight()
        {
            if (iMoveRight_Menu != null)
                iMoveRight_Menu();
        }
        public void ConfirmAction()
        {
            if (iConfirm_Menu != null)
                iConfirm_Menu();
        }


        int menu_selezionato = 2;

        public void Update(GameTime gameTime, out int SelectedMenu)
        {

            oldKb = kb;
            kb = Keyboard.GetState();

            rotateStar += (float)gameTime.ElapsedGameTime.TotalSeconds * 50;

            SelectedMenu = menu_selezionato;
            menu_selezionato = 2;
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, Matrix.CreateScale(rendering_data.screenWidth / 100.0f, rendering_data.screenHeight / 100.0f, 1.0f));
            spriteBatch.Draw(tutorial, new Rectangle(0, 0, 100, 100), Color.White);

            spriteBatch.DrawString(menufont, voiceText[0], new Vector2(80, 90), (selectedVoice == (int)TutorialMenu.voice.Indietro) ? Color.Orange : Color.White, 0, Vector2.Zero, 0.07f, SpriteEffects.None, 0f);

            spriteBatch.Draw(selectionTexture, new Vector2(76, 92), null, Color.White, MathHelper.ToRadians(rotateStar), new Vector2(selectionTexture.Width / 2, selectionTexture.Height / 2), 0.01f, SpriteEffects.None, 0.0f);

            spriteBatch.End();
        }
    }

}
